<script setup>
import {onMounted, ref} from 'vue'
import {useRoute} from 'vue-router'
import service from '@/api/request0.js'
import router from "@/router/index.js";

const route = useRoute()
const product = ref({})

const fetchProductDetail = async () => {
  try {
    product.value = await service.get(`/product/${route.params.productId}`)
  } catch (error) {
    console.error('获取商品详情失败:', error)
  }
}

onMounted(fetchProductDetail)
</script>


<template>
  <div class="product-detail-container">
    <h2 class="product-title">{{ product.name }}</h2>

    <div class="product-content">


      <div class="info-section">
        <div class="detail-card">
          <div class="info-item">
            <label>商品ID：</label>
            <span class="value">{{ product.productId }}</span>
          </div>
          <div class="info-item">
            <label>分类ID：</label>
            <span>{{ product.categoryId }}</span>
          </div>
          <div class="info-item">
            <label>商品名称：</label>
            <span>{{ product.name }}</span>
          </div>
          <div class="info-item description">

            <div class="description-box">
              <h3>商品详情</h3>
              <div class="description-content" v-html="product.description"></div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <button class="action-button back-button" @click="router.go(-1)">
      ← 返回列表
    </button>
  </div>
</template>

<style scoped>
.product-detail-container {
  padding: 2rem;
  max-width: 1280px;
  margin: 0 auto;
}

.product-title {
  font-size: 2rem;
  color: #2c3e50;
  margin-bottom: 1.5rem;
}

.product-content {
  display: block;
}



.view-items {
  display: inline-flex;
  align-items: center;
  padding: 12px 24px;
  background: linear-gradient(135deg, #42b983 0%, #33a06f 100%);
  color: white;
  border-radius: 30px;
  text-decoration: none;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
  position: relative;
}

.view-items::after {
  content: '←';
  margin-left: 8px;
  font-weight: 700;
  opacity: 0.8;
}

.view-items:hover {
  background: linear-gradient(135deg, #33a06f 0%, #2a8b5f 100%);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
  transform: translateY(-2px);
}

.detail-card {
  padding: 1.5rem;
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  transition: transform 0.3s ease;
}

.detail-card:hover {
  transform: translateY(-2px);
}

.description-box {
  background: #f8f9fa;
  padding: 1rem;
  border-radius: 8px;
  margin-top: 1.5rem;
}

.action-button {
  padding: 12px 32px;
  font-size: 1rem;
  border-radius: 30px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@media (max-width: 768px) {
  .product-title {
    font-size: 1.5rem;
  }
  .detail-card {
    padding: 1rem;
  }
  .action-button {
    width: 100%;
    padding: 14px;
  }
}
</style>